Preview - Programming: It's For Everyone!

Commands & Properties - Actions and States


programming language is just like any other language.

English is a language made up of words and syntax (think grammar, punctuation, etc.). The combination of using words and syntax allows for us to communicate with other people who speak English! But in English, there are situations where weirdness prevents us from understanding the meaning behind a sentence. Take, for example, the sentence: "I never said they stole my money." We might assume it means a particular thing, but if you said this sentence out loud...most people would interpret the meaning based on which word you placed emphasis (which we show in bold below) on:

I never said they stole my money. — Someone else said it. 

never said they stole my money. — I didn't say it. 

I never said they stole my money. — I only implied it. 

I never said they stole my money. — I said someone did, not necessarily them. 

I never said they stole my money. — I considered it borrowed. 

I never said they stole my money. — Only that they stole money,  not necessarily my own. 

I never said they stole my money. — They stole something of mine, not my money. 

Computers can't deal (easily at least) with this ambiguity. So in a programming language, we limit ourselves to particular commands that are defined very specifically such that there is no ambiguity when you give the computer that command. Below, you'll interact with a microworld where you have the ability to ask the computer to run or process some commands.


Questions

Please answer the questions below.

To the right, you'll see exactly what everyone expects to see on a typical day: a turtle on a chessboard (or a grid of patches) with some lava on it. Your goal? Guide the turtle to the safety of the violet (yes, that's violet not "purple") patch.

At the top of the board is a RESET button. Every time you click this button, the board will be randomly regenerated, placing the turtle, lava, and violet goal in random new locations.

At the bottom of the board you should see three buttons:

  • TURN LEFT
  • FORWARD
  • TURN RIGHT

These are the only commands that exist in your world here. Each time you click one of the buttons, the turtle executes the command. Try using those buttons to guide the turtle to the goal!

 

In this simulation, you only had three commands. In other words, the computer only understood these three actions of turning left, turning right, and going forward. But say we wanted the turtle to go backwards one square. Is there any way we could combine these three commands into a BACKWARDS command? In the space below, type a sequence of button presses you might use to go backwards!


Surprise! You just wrote your first computer program! A program is just a collection of instructions that a computer can run. When you combined the existing commands to go BACKWARDS, you wrote a program. 

 

Now that you've gotten command of commands, let's turn our attention to another aspect of: properties.

Our favorite turtle is back on board! You've got all the same buttons at your disposal, but you've got some interesting monitors down at the bottom of the screen. You should see three different displays:

  • POSITION (where am i?)
  • HEADING (what direction am i facing?)
  • WHAT-IS-AHEAD (what is ahead of me?)

Each of these monitors shows the current value of a property for your turtle-buddy. Just like an object in the real world has properties (e.g. color, texture, hardness, etc.), computational objects have these properties too!

Properties are very important to understand because they can have an effect on the outcome of commands. For instance, does the FORWARD button always do the same thing? Or does it depend on what the value of HEADING is for the turtle? 

Move your turtle around and watch how the value in each of these three different properties changes as you move. Use these explorations to answer the questions below.

 

Where is the "origin" or position (0,0) on our board?

top left
bottom left
bottom right
top right
center

Use the table below to map the numerical HEADING value you saw during your explorations to a more understandable DIRECTION (i.e. the direction the turtle is facing) that is either North (up), South (down), East (right), or West (left). Hint: you can use the green "plus" button to add a row to the table.


What does the WHAT-IS-AHEAD property read as when a turtle is facing a direction where there are no more patches in front of it?

lava
safe
none
edge

Notes

These notes will appear on every page in this lesson so feel free to put anything here you'd like to keep track of.